package com.vincent.kdp.Activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.decoration.DividerDecoration;
import com.vincent.kdp.R;
import com.vincent.kdp.adapter.CounterViewHolder;
import com.vincent.kdp.bean.RxBusPosBean;
import com.vincent.kdp.ui.bean.response.Counter;
import com.vincent.kdp.ui.bean.response.CounterOutput;
import com.jude.rollviewpager.Util;
import com.vincent.kdp.util.RxBus;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ChooseDepartActivity extends AppCompatActivity {

    @Bind(R.id.bottom_line_tv)
    TextView bottomLineTv;
    @Bind(R.id.back_img)
    ImageView backImg;
    @Bind(R.id.toolbar_center_tv)
    TextView toolbarCenterTv;
    @Bind(R.id.layout_toolbar_two)
    RelativeLayout layoutToolbarTwo;
    @Bind(R.id.choose_lv)
    EasyRecyclerView chooseLv;


    CounterOutput bean;

    private RecyclerArrayAdapter<Counter> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_depart);
        ButterKnife.bind(this);
        toolbarCenterTv.setText("选择柜台");
        bean = (CounterOutput) getIntent().getExtras().getSerializable("bean");


        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        chooseLv.setLayoutManager(layoutManager);
        DividerDecoration itemDecoration = new DividerDecoration(Color.parseColor("#CDCDCD"), Util.dip2px(this, 0.2f), Util.dip2px(this, 10), Util.dip2px(this, 10));
        chooseLv.addItemDecoration(itemDecoration);
        chooseLv.setAdapterWithProgress(adapter = new RecyclerArrayAdapter<Counter>(this) {
            @Override
            public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
                CounterViewHolder pvh;
                pvh = new CounterViewHolder(parent);
                return pvh;
            }
        });

        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {


                String id = adapter.getAllData().get(position).getId();
                String name=adapter.getAllData().get(position).getCounterName();
                RxBus.getInstance().post(new RxBusPosBean(1,id,name));
                ChooseDepartActivity.this.finish();

            }
        });
        adapter.addAll(bean.getData());
    }

    @OnClick(R.id.back_img)
    public void onViewClicked() {
        finish();
    }
}
